package com.zhuoya.healthcard.util;

import org.apache.commons.lang3.*;

public final class SensitiveInfoUtils {
    public static String address(final String s, final int n) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        final int length = StringUtils.length(s);
        return StringUtils.rightPad(StringUtils.left(s, length - n), length, "*");
    }

    public static String bankCard(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.left(s, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(s, 4), StringUtils.length(s), "*"), "******"));
    }

    public static String chineseName(final String s) {
        return s.replace(s.substring(0, 1), "*");
    }

    public static String chineseName(final String s, final String s2) {
        if (StringUtils.isBlank(s) || StringUtils.isBlank(s2)) {
            return "";
        }
        if (s.length() > 1) {
            final String left = StringUtils.left(s, s.length());
            final StringBuilder sb = new StringBuilder();
            sb.append(s);
            sb.append(s2);
            return StringUtils.rightPad(left, StringUtils.length(sb.toString()), "*");
        }
        final StringBuilder sb2 = new StringBuilder();
        sb2.append(s);
        sb2.append(s2);
        return chineseName(sb2.toString());
    }

    public static String cnapsCode(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.rightPad(StringUtils.left(s, 2), StringUtils.length(s), "*");
    }

    public static String email(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        final int index = StringUtils.indexOf(s, "@");
        if (index <= 1) {
            return s;
        }
        return StringUtils.rightPad(StringUtils.left(s, 1), index, "*").concat(StringUtils.mid(s, index, StringUtils.length(s)));
    }

    public static String fixedPhone(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.leftPad(StringUtils.right(s, 4), StringUtils.length(s), "*");
    }

    public static String idCard(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.left(s, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(s, 4), StringUtils.length(s), "*"), "******"));
    }

    public static String idCardNum(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.leftPad(StringUtils.right(s, 4), StringUtils.length(s), "*");
    }

    public static String mobilePhone(final String s) {
        if (StringUtils.isBlank(s)) {
            return "";
        }
        return StringUtils.left(s, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(s, 4), StringUtils.length(s), "*"), "***"));
    }
}
